﻿using System;
using System.Timers;

namespace BaseSyntax.Event.EventWithArgs
{
	// 先定义委托类型
	// public delegate void ListenerDel(string msg);
	
	public class Connection
	{
		public event EventHandler<EventArg> Handle;
		
		public string Name
		{
			get;
			set;
		}
		
		// public event ListenerDel listener;
		private Timer timer;

		public Connection()
		{
			timer = new Timer(1000);
			timer.Elapsed += new ElapsedEventHandler(TimerHandle);
		}
		
		public void Connect()
		{
			timer.Start();
		}
		
		Random ran = new Random();
		public void TimerHandle(object o1, ElapsedEventArgs e)
		{
			// Console.WriteLine("timer Handle");
			Handle?.Invoke(o1, new EventArg(ran.Next(1000).ToString()));
		}
	}
}